﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class InstalledSoftware_InstalledSoftware : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtSoftwareID.Text = Session["softwareID"].ToString();
            txtComputerID.Text = Session["computerID"].ToString();
            Session.Remove("softwareID");
            Session.Remove("computerID");
        }
    }

    protected void btnCancle_Click(object sender, EventArgs e)
    {
        //txtComputerID.Text = "";
        //txtSoftwareID.Text = "";
        txtInstallDate.Text = "";
        txtUpdateDate.Text = "";
        txtUpdateVersion.Text = "";
    }
    protected void btnInstallSoftware_Click(object sender, EventArgs e)
    {
        InstalledSoftware instalSoftware = new InstalledSoftware();
        instalSoftware.computers_ID = Int32.Parse(txtComputerID.Text);
        instalSoftware.software_ID = Int32.Parse(txtSoftwareID.Text);
        instalSoftware.install_Date = DateTime.Parse(txtInstallDate.Text);
        instalSoftware.update_Date = DateTime.Parse(txtUpdateDate.Text);
        instalSoftware.update_Version = txtUpdateVersion.Text;

        SoftwareDBConnection softwareConn = new SoftwareDBConnection();
        softwareConn.installSoftwareOnPC(instalSoftware);

        Software software = softwareConn.getSoftwareByID(instalSoftware.software_ID);

        FeedBack feedback = new FeedBack();
        feedback.success = 1;
        feedback.lastPageURL = "Assets.aspx";
        feedback.message = "You have successfully added a record of the instalation of the software: " + 
                            software.software_Name+" ("+software.software_ID+") on the computer: "+instalSoftware.computers_ID+" (ID).";
        Session["Feedback"] = feedback;
        Server.Transfer("../Feedback.aspx");

    }


}